﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AWA.VAT.GuestRelations.Models;
using System.Windows.Forms;
using AWA.VAT.GuestRelations.Views;

namespace AWA.VAT.GuestRelations.Controllers
{
    public class LoadController
    {
        LoadForm _form;
        LoadModel _model;
        string _fileLocation;

        public LoadController()
        {
            _form = new LoadForm(this);
        }

        public void Execute()
        {
            _form.ShowDialog();
        }

        public void LoadSpreadsheet()
        {
            OpenFileDialog dialog = new OpenFileDialog();
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this._fileLocation = dialog.FileName;
                _form.ReadEnabled = true;
            }
        }

        public void LoadExcelFileContents()
        {
            if (String.IsNullOrEmpty(_fileLocation))
                LoadSpreadsheet();

            if (!String.IsNullOrEmpty(_fileLocation))
            {
                _model.LoadExcelFileContents(_fileLocation);
                _form.SaveEnabled = true;
            }
        }

        public void CommitToDB()
        {
            _model.CommitFileContentsToDB();
            _form.SaveEnabled = false;
        }
    }
}
